﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Xml.Serialization;

using Gonte.Reflection;

namespace Gonte.Xml.Serialization
{
    public class XmlArrayDeserializer
        : XmlListDeserializer
    {
        #region Constructors

        protected internal XmlArrayDeserializer(Object @object)
            : base(@object)
        {
        }

        #endregion

        #region Overridables

        protected override void OnDeserializedItem(Object item)
        {
            temporaryList_.Add(item);
        }

        protected override void OnAfterReading()
        {
            // Create the array from the temporary list
            object_ = Array.CreateInstance(((Array)object_).GetType().GetElementType(), temporaryList_.Count);
            temporaryList_.CopyTo((Array)object_, 0);

            base.OnAfterReading();
        }

        #endregion

        #region Fields

        private ArrayList temporaryList_ = new ArrayList(); 

        #endregion
    }
}
